package com.deyuanyun.pic.pbf.controller.dto.validata;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;

import com.deyuanyun.pic.common.util.ObjectUtil;
import com.deyuanyun.pic.common.util.StringUtils;
import com.deyuanyun.pic.common.util.web.RequestResponseContext;
import com.deyuanyun.pic.common.validator.vinterface.ValidateInterface;
import com.deyuanyun.pic.settings.support.utils.PipeDictUtils;

public class PipeSegmentRequestValidata implements ValidateInterface {

	@Override
	public <T, E,C> boolean apply(T t, E e,C c) {
		
		if(ObjectUtil.isNotNullEmpty(t)){
			try {
				String lineName = BeanUtils.getProperty(c,"pipeLineName");
				String segmentName = (String)t;
				String segmentId = PipeDictUtils.getSegmentByName(lineName, segmentName);
				/*
				//用检测管段
				RepairTaskService repairTaskService= SpringAppliction.getBean(RepairTaskService.class);
				Map<String,Object> map = repairTaskService.queryInspSegmentByName(lineName, segmentName);
				if(map == null || map.isEmpty()){
				    return false;
				}
				String segmentId = (String)map.get("ID_");
				*/
				if (StringUtils.isEmpty(segmentId)){
				    return false;
				}
				HttpServletRequest request = RequestResponseContext.getRequest();
                String segmentId_request = request.getParameter("pipeSegmentId");
				
                return segmentId.equals(segmentId_request);

			} catch (Exception e1) {
				e1.printStackTrace();
				return false;
			}

		}
		return true;
	}

	@Override
	public String getName() {
		
		return null;
	}

}
